<?php
	class EditorAction extends Action{
		
		public function createNewBase($sid=""){
			$method=$_POST["method"];
			if (!isset($_POST["submit"])){//如果不是从表单提交的数据则直接显示页面
				$this->assign("method",$method);
				$base=M("Baseinfo");
				$info=$base->where("sid=".$sid)->select();
				$this->assign("sid",$sid);
				$this->assign("oneDetail",$info[0]);
				echo $this->fetch();
				exit();
			}
			unset($_POST["submit"]);
			$e=D("Editor");
			
			$result=$e->createBaseInfo($_POST);
			if($result==1){
				echo "数据提交成功";
			}else{
				echo $result."\n数据提交失败，请检查您的输入";
			}
			
		}
		
		public function createNewFamily($sid=""){
			$base=D("Base");
			@$stInfo["sid"]=$sid;
			$method=$_POST["method"];
			@$stInfo["stname"]=$base->getSIDinfo($sid,"name","name");
			@$stInfo["major"]=$base->getSIDinfo($sid,"major","name");
			@$stInfo["class"]=substr($sid,0,2)."级 ".$base->getSIDinfo($sid,"class","name");
			if(!isset($_POST["submit"])){
				/*  */
				$f=M("Familyinfo");
				$info=$f->where("sid=".$stInfo["sid"])->select();
				if (empty($info)) {
					$this->assign("method","create");
				}else{
					$this->assign("method","modify");
				}
				$this->assign("familyInfo",$info);
					
				$this->assign("editorInfo",$stInfo);
				echo $this->fetch();
				exit();
			}
			unset($_POST["submit"]);
			$e=D("Editor");
			$result=$e->createFamilyInfo($stInfo["sid"],$_POST,$method);
			if($result==1){
				echo "数据提交成功";
			}else{
				echo $result."\n数据提交失败，请检查您的输入";
			}
		}
		
		public function createNewSanction($sid=""){
			$base=D("Base");
			@$stInfo["sid"]=$sid;
			$this->assign("sid",$sid);
			$year=$_POST["year"];
			$this->assign("year",$year);
			@$stInfo["stname"]=$base->getSIDinfo($sid,"name","name");
			@$stInfo["major"]=$base->getSIDinfo($sid,"major","name");
			@$stInfo["class"]=substr($sid,0,2)."级 ".$base->getSIDinfo($sid,"class","name");
			if (!isset($_POST["submit"])){
				$sanction=M("Sanctioninfo");
				$where["sid"]=$sid;
				$where["year"]=$year;
				$info=$sanction->where($where)->select();
				$tmp=explode("&", $info[0]["bkms"]);
				$info[0]["up"]["bkms"]=$tmp[0];
				$info[0]["down"]["bkms"]=$tmp[1];
				$tmp=explode("&", $info[0]["cxms"]);
				$info[0]["up"]["cxms"]=$tmp[0];
				$info[0]["down"]["cxms"]=$tmp[1];
				unset($info[0]["bkms"]);
				unset($info[0]["cxms"]);
				$this->assign("sanction",$info[0]);
				$this->assign("editorInfo",$stInfo);
				echo $this->fetch();
				exit();
			}
			$san=D("Editor");
			unset($_POST["submit"]);
			$result=$san->createSanctionInfo($sid,$_POST);
			if($result==1){
				echo "操作成功";
			}else{
				echo $result;
			}
		}
		
		
		public function createNewParty($sid=""){
			$base=D("Base");
			@$stInfo["sid"]=$sid;
			$this->assign("sid",$sid);
			$method=$_POST["method"];//初始化页面是告知页面状态
			@$stInfo["stname"]=$base->getSIDinfo($sid,"name","name");
			@$stInfo["major"]=$base->getSIDinfo($sid,"major","name");
			@$stInfo["class"]=substr($sid,0,2)."级 ".$base->getSIDinfo($sid,"class","name");
			
			if(!isset($_POST["submit"])){
				$this->assign("method",$method);
				$this->assign("editorInfo",$stInfo);
				$info=M("Partyinfo");
				$partyInfo=$info->where("sid=".$sid)->select();
				$this->assign("partyInfo",$partyInfo[0]);
				echo $this->fetch();
				exit();
			}
			unset($_POST["submit"]);
			$party=D("Editor");
			unset($_POST["method"]);
			$result=$party->createPartyInfo($sid,$_POST);
			if($result==1){
				echo "操作成功!";
			}else{
				echo $result;
			}
			
		}
		public function createNewClassJob($sid=""){
			$base=D("Base");
			@$stInfo["sid"]=$sid;
			$this->assign("sid",$sid);
			@$stInfo["stname"]=$base->getSIDinfo($sid,"name","name");//获得正在编辑的学生姓名
			@$stInfo["major"]=$base->getSIDinfo($sid,"major","name");//获得正在编辑的学生专业
			@$stInfo["class"]=substr($sid,0,2)."级 ".$base->getSIDinfo($sid,"class","name");//获得正在编辑的学生班级
			$grade=$base->getSIDinfo($sid,"grade","name");//获得正在编辑的学生年级
			for($i=0;$i<5;$i++){
				$years[$i+1]=$grade+$i;//获得该学生在校的年份
			}
			$this->assign("years",$years);	
			if(!isset($_POST["submit"])){
				$this->assign("editorInfo",$stInfo);
				$info=M("Classjobinfo");
				$tmp=$info->where("sid=".$sid)->select();
				for($i=0;$i<count($tmp);$i++){//将该学生的数据整合到一起去
					$year=$tmp[$i]["year"];
					$classJobInfo[$year]["year"]=$year;
					if($tmp[$i]["term"]=="up"){
						$classJobInfo[$year]["up"]["job"]=$tmp[$i]["job"];
					}else{
						$classJobInfo[$year]["down"]["job"]=$tmp[$i]["job"];
					}
				
				}
				$this->assign("classJobInfo",$classJobInfo);
				echo $this->fetch();
				exit();
			}
			unset($_POST["submit"]);
			$classjob=D("Editor");
			$result=$classjob->createClassJobInfo($sid,$_POST,$grade);//对信息创建或编辑
			if($result==1){
				echo "操作成功!";
			}else{
				echo $result;
			}
				
		}
		public function createNewRemark($sid=""){
			$base=D("Base");
			@$stInfo["sid"]=$sid;
			$this->assign("sid",$sid);
			@$stInfo["stname"]=$base->getSIDinfo($sid,"name","name");//获得正在编辑的学生姓名
			@$stInfo["major"]=$base->getSIDinfo($sid,"major","name");//获得正在编辑的学生专业
			@$stInfo["class"]=substr($sid,0,2)."级 ".$base->getSIDinfo($sid,"class","name");//获得正在编辑的学生班级
			if(!isset($_POST['submit'])){
				$this->assign("editorInfo",$stInfo);//绑定学生信息
				$info=M("Remark");
				$remark=$info->where("sid=".$sid)->getField("remark");
				$this->assign("remark",$remark);
				echo $this->fetch();
				exit();
			}
			unset($_POST["submit"]);
			$remark=D("Editor");
			$result=$remark->createRemark($sid,$_POST);//同时处理创建或编辑
			if ($result==1) {
				echo "数据处理成功";
			}else{
				echo "数据处理失败";
			}
			
		}

		public function createNewHelp($sid=""){
			$base=D("Base");
			@$stInfo["sid"]=$sid;
			$this->assign("sid",$sid);
			@$stInfo["stname"]=$base->getSIDinfo($sid,"name","name");//获得正在编辑的学生姓名
			@$stInfo["major"]=$base->getSIDinfo($sid,"major","name");//获得正在编辑的学生专业
			@$stInfo["class"]=substr($sid,0,2)."级 ".$base->getSIDinfo($sid,"class","name");//获得正在编辑的学生班级
			if(!isset($_POST['submit'])){
				$this->assign("editorInfo",$stInfo);//绑定学生信息
				$info=M("Helpinfo");
				$help=$info->where("sid=".$sid)->select();
				$this->assign("help",$help[0]);
				echo $this->fetch();
				exit();
			}
			unset($_POST["submit"]);
			$help=D("Editor");
			$result=$help->createHelpInfo($sid,$_POST);//同时处理创建或编辑
			if ($result==1) {
				echo "数据处理成功";
			}else{
				echo "数据处理失败";
			}
		}
		public function createbys(){
			$grade=$_POST["getgrade"];
			$major=$_POST["getmajor"];
			$class=$_POST["getclass"];
			if (empty($grade)||empty($major)||empty($class)) {
				echo $this->fetch();
				exit();
			}
			$base=M("Baseinfo");
			$where["grade"]=$grade;
			$where["major"]=$major;
			$where["class"]=$class;
			$info=$base->where($where)->field("sid,name,grade,major,class,isby")->select();
			for($i=0;$i<count($info);$i++){
				$info[$i]["index"]=$i;
				if((int)$info[$i]["isby"]>1000){
					$info[$i]["isby"]="checked";
				}else{
					$info[$i]["isby"]="";
				}
			}
			$this->assign("oneDetail",$info);
			echo $this->fetch("Page:createbys");
		}
		
		public function dealByDetail($sid=""){
			$base=D("Base");
			@$stInfo["sid"]=$sid;
			$this->assign("sid",$sid);
			@$stInfo["stname"]=$base->getSIDinfo($sid,"name","name");//获得正在编辑的学生姓名
			@$stInfo["major"]=$base->getSIDinfo($sid,"major","name");//获得正在编辑的学生专业
			@$stInfo["class"]=substr($sid,0,2)."级 ".$base->getSIDinfo($sid,"class","name");//获得正在编辑的学生班级
			$by=M("Graduate");
			$info=$by->where("sid=".$sid)->select();
			$this->assign("byinfo",$info[0]);
			$this->assign("editorInfo",$stInfo);//绑定学生信息
			$this->assign("dealURL",U("Request/dealByDetail","sid=".$sid));
			$this->display();
		}
	}
?>
